package org.banxico.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	
	static{ //Static initializer to create SessionFactory Singleton
		try{
			sessionFactory = new Configuration().configure().buildSessionFactory();
		}catch (Throwable e) {
			// TODO: handle exception
			System.err.println("Initial SessionFactory creation failed." + e);
			throw new ExceptionInInitializerError(e);
		}
	}
	
	public static SessionFactory getSessionFactory(){
		return sessionFactory;
	}
	
	//Helpers para ahorrarnos codigo
	public static Session getCurrentSession(){
		return sessionFactory.getCurrentSession();
	}
	public static Session openSession(){
		return sessionFactory.openSession();
	}
	//Fin helpers
	
}
